<template>
    <div class="edu-page-warp">
        <InnerBreadcrumb v-model="indexKey" :path="breadPath" :showBack="true" />
        <div v-show="indexKey == '1'">
            <div class="edu-page-title">
                <span
                    v-for="item in tabs"
                    :key="item.key"
                    @click="activeTab = item.key"
                    :class="{ active: activeTab == item.key }"
                >
                    {{ item.label }}
                </span>
            </div>
            <!-- 学生 -->
            <div id="studentBox" v-if="activeTab == 'student'" key="studentBox">
                <ConditionCard
                    :expand="false"
                    shadow="never"
                    body-style="padding: 24px 24px 6px 24px;"
                    @search="queryUserList"
                    @reset="resetStuQueryForm"
                >
                    <el-form :model="studentForm" ref="studentForm" label-width="150px">
                        <el-row>
                            <el-col :span="8">
                                <el-form-item label="培养层次 : ">
                                    <el-select
                                        v-model="studentForm.trainingLevel"
                                        style="width: 100%"
                                    >
                                        <el-option
                                            v-for="item in options.trainingLevel"
                                            :key="item.value"
                                            :label="item.label"
                                            :value="item.value"
                                        ></el-option>
                                    </el-select>
                                </el-form-item>
                            </el-col>
                            <el-col :span="8" v-if="isShowDegreeType">
                                <el-form-item label="入学季节 : ">
                                    <el-select
                                        v-model="studentForm.enrolSeason"
                                        style="width: 100%"
                                    >
                                        <el-option
                                            v-for="item in options.enrolSeason"
                                            :key="item.value"
                                            :label="item.label"
                                            :value="item.value"
                                        ></el-option>
                                    </el-select>
                                </el-form-item>
                            </el-col>
                            <el-col :span="8">
                                <el-form-item label="年级 : ">
                                    <el-select
                                        v-model="studentForm.grade"
                                        @change="changeFaculty"
                                        style="width: 100%"
                                    >
                                        <el-option
                                            v-for="item in options.grade"
                                            :key="item.value"
                                            :label="item.label"
                                            :value="item.value"
                                        ></el-option>
                                    </el-select>
                                </el-form-item>
                            </el-col>
                            <el-col :span="8">
                                <el-form-item label="学院 : ">
                                    <el-select
                                        v-model="studentForm.faculty"
                                        @change="changeFaculty"
                                        style="width: 100%"
                                    >
                                        <el-option
                                            v-for="item in options.faculty"
                                            :key="item.value"
                                            :label="item.label"
                                            :value="item.value"
                                        ></el-option>
                                    </el-select>
                                </el-form-item>
                            </el-col>
                            <el-col :span="8" v-if="!isShowDegreeType">
                                <el-form-item label="专业 : ">
                                    <el-select v-model="studentForm.profession" style="width: 100%">
                                        <el-option
                                            v-for="item in options.profession"
                                            :key="item.value"
                                            :label="item.label"
                                            :value="item.value"
                                        ></el-option>
                                    </el-select>
                                </el-form-item>
                            </el-col>
                            <el-col :span="8" v-if="isShowDegreeType">
                                <el-form-item label="学位类型 : ">
                                    <el-select
                                        v-model="studentForm.degreeType"
                                        @change="changeFaculty"
                                        style="width: 100%"
                                    >
                                        <el-option
                                            v-for="item in options.degreeType"
                                            :key="item.value"
                                            :label="item.label"
                                            :value="item.value"
                                        ></el-option>
                                    </el-select>
                                </el-form-item>
                            </el-col>
                            <el-col :span="8">
                                <el-form-item label="专业 : " v-if="isShowDegreeType">
                                    <el-select v-model="studentForm.profession" style="width: 100%">
                                        <el-option
                                            v-for="item in options.profession"
                                            :key="item.value"
                                            :label="item.label"
                                            :value="item.value"
                                        ></el-option>
                                    </el-select>
                                </el-form-item>
                            </el-col>
                            <el-col :span="8">
                                <el-form-item label="在校状态 : ">
                                    <el-select
                                        v-model="studentForm.leaveSchool"
                                        style="width: 100%"
                                    >
                                        <el-option
                                            v-for="item in options.leaveSchool"
                                            :key="item.value"
                                            :label="item.label"
                                            :value="item.value"
                                        ></el-option>
                                    </el-select>
                                </el-form-item>
                            </el-col>
                        </el-row>
                    </el-form>
                </ConditionCard>
                <el-card shadow="never">
                    <div class="edu-page-title authority-actionBar">用户列表</div>
                    <el-row :gutter="20" class="border-bottom" style="height: 56px">
                        <el-col :span="6">
                            <el-input
                                placeholder="账号或用户名"
                                v-model="studentForm.name"
                                clearable
                                @keyup.enter.native="queryUserList"
                                prefix-icon="el-icon-search"
                            ></el-input>
                        </el-col>
                        <el-col :span="2">
                            <el-button @click="queryUserList">查询</el-button>
                        </el-col>
                        <el-col :span="16">
                            <div class="float-right">
                                <el-button @click="showBatchFn" v-premit="'add_user_to_group'">
                                    批量操作
                                </el-button>
                                <el-button @click="showAddToGroupFn" v-premit="'add_user_to_group'">
                                    添加到组
                                </el-button>
                                <el-button @click="freeze(0)" v-premit="'add_user_to_group'">
                                    激活
                                </el-button>
                                <el-button @click="freeze(1)" v-premit="'add_user_to_group'">
                                    冻结
                                </el-button>
                            </div>
                        </el-col>
                    </el-row>
                    <edu-table
                        stripe
                        size="small"
                        :order="false"
                        :data="students"
                        ref="stuUserTable"
                        style="width: 100%"
                        tooltip-effect="light"
                        :total="studentForm.total"
                        :pageNum="studentForm.pageNum_"
                        :page-size="studentForm.pageSize_"
                        :isRowClickChangeRowSelection="false"
                        @page-change="(params) => handleCurrentChange(params, 'studentForm')"
                        @selection-change="chooseUsers"
                    >
                        <el-table-column show-overflow-tooltip label="账号" width="80">
                            <template slot-scope="scope">{{ scope.row.studentId }}</template>
                        </el-table-column>
                        <el-table-column show-overflow-tooltip label="用户名" width="100">
                            <template slot-scope="scope">
                                <el-button
                                    type="text"
                                    @click="showStudentDetail(scope.row.studentId)"
                                >
                                    {{ scope.row.name }}
                                </el-button>
                            </template>
                        </el-table-column>
                        <el-table-column label="培养层次" width="80">
                            <template slot-scope="scope">
                                {{ scope.row.trainingLevelI18n }}
                            </template>
                        </el-table-column>
                        <el-table-column v-if="isShowDegreeType" label="入学季节" width="80">
                            <template slot-scope="scope">{{ scope.row.enrolSeasonI18n }}</template>
                        </el-table-column>
                        <el-table-column label="年级" width="80">
                            <template slot-scope="scope">{{ scope.row.grade }}</template>
                        </el-table-column>
                        <el-table-column show-overflow-tooltip label="学院">
                            <template slot-scope="scope">
                                <span>{{ scope.row.facultyI18n }}</span>
                            </template>
                        </el-table-column>
                        <el-table-column
                            show-overflow-tooltip
                            label="学位类型"
                            v-if="isShowDegreeType"
                        >
                            <template slot-scope="scope">
                                <span>{{ scope.row.degreeTypeI18n }}</span>
                            </template>
                        </el-table-column>
                        <el-table-column show-overflow-tooltip label="专业">
                            <template slot-scope="scope">
                                <span>{{ scope.row.professionI18n }}</span>
                            </template>
                        </el-table-column>
                        <el-table-column show-overflow-tooltip label="在校状态">
                            <template slot-scope="scope">
                                <span>{{ scope.row.leaveSchoolI18n }}</span>
                            </template>
                        </el-table-column>
                        <el-table-column show-overflow-tooltip label="账号状态">
                            <template slot-scope="scope">
                                <el-button
                                    :type="scope.row.accountDisabled ? 'warning' : 'success'"
                                    size="mini"
                                >
                                    {{ scope.row.accountDisabled ? '冻结' : '正常' }}
                                </el-button>
                            </template>
                        </el-table-column>
                        <el-table-column show-overflow-tooltip label="联系电话" width="114">
                            <template slot-scope="scope">
                                <span>{{ scope.row.phoneNumber }}</span>
                            </template>
                        </el-table-column>
                        <el-table-column show-overflow-tooltip label="联系邮箱" width="114">
                            <template slot-scope="scope">
                                <span>{{ scope.row.email }}</span>
                            </template>
                        </el-table-column>
                        <el-table-column label="操作" width="200" fixed="right">
                            <template slot-scope="scope">
                                <el-button
                                    type="text"
                                    @click="checkAuthoritiesFn(scope.row.studentId, 2)"
                                >
                                    查看权限
                                </el-button>
                                <el-button
                                    type="text"
                                    @click="addRowToGroupFn(scope.row, scope.row.studentId)"
                                    v-premit="'add_user_to_group'"
                                >
                                    添加到组
                                </el-button>
                                <el-button
                                    type="text"
                                    @click="showRelatedGroupsFn(scope.row.studentId)"
                                >
                                    已关联组
                                </el-button>
                            </template>
                        </el-table-column>
                    </edu-table>
                </el-card>
            </div>
            <!-- 教师 -->
            <div id="teacherBox" v-else-if="activeTab == 'teacher'">
                <el-card shadow="never">
                    <el-row class="border-bottom" style="height: 56px" :gutter="20">
                        <el-col :span="6">
                            <el-input
                                placeholder="账号或用户名"
                                v-model="teacherForm.condition"
                                prefix-icon="el-icon-search"
                                clearable
                                @keyup.enter.native="queryUserList"
                            ></el-input>
                        </el-col>
                        <el-col :span="2">
                            <el-button @click="queryUserList" @keyup.enter.native="queryUserList">
                                查询
                            </el-button>
                        </el-col>
                        <el-col :span="4">
                            <div class="empty-box"></div>
                        </el-col>
                        <el-col :span="12">
                            <div class="float-right">
                                <el-button @click="showAddToGroupFn" v-premit="'add_user_to_group'">
                                    添加到组
                                </el-button>
                                <el-button @click="freeze(0)" v-premit="'add_user_to_group'">
                                    激活
                                </el-button>
                                <el-button @click="freeze(1)" v-premit="'add_user_to_group'">
                                    冻结
                                </el-button>
                            </div>
                        </el-col>
                    </el-row>
                    <edu-table
                        stripe
                        :order="false"
                        :data="teachers"
                        style="width: 100%"
                        ref="teacherUserTable"
                        tooltip-effect="light"
                        :total="teacherForm.total"
                        :pageNum="teacherForm.pageNum_"
                        :page-size="teacherForm.pageSize_"
                        :isRowClickChangeRowSelection="false"
                        @page-change="(params) => handleCurrentChange(params, 'teacherForm')"
                        @selection-change="chooseUsers"
                    >
                        <el-table-column
                            prop="code"
                            show-overflow-tooltip
                            label="账号"
                        ></el-table-column>
                        <el-table-column
                            prop="name"
                            show-overflow-tooltip
                            label="用户名称"
                            min-width="80"
                        ></el-table-column>
                        <el-table-column show-overflow-tooltip label="所在学院" min-width="80">
                            <template slot-scope="scope">
                                <span>{{ scope.row.facultyI18n }}</span>
                            </template>
                        </el-table-column>
                        <el-table-column show-overflow-tooltip label="管理学院" min-width="80">
                            <template slot-scope="scope">
                                <span>{{ scope.row.manageFacultysI18n }}</span>
                            </template>
                        </el-table-column>
                        <el-table-column show-overflow-tooltip label="专业">
                            <template slot-scope="scope">
                                <span>{{ scope.row.profession }}</span>
                            </template>
                        </el-table-column>
                        <el-table-column show-overflow-tooltip label="教师资格" width="80">
                            <template slot-scope="scope">
                                {{ scope.row.qualificationI18n }}
                            </template>
                        </el-table-column>
                        <el-table-column show-overflow-tooltip label="职称">
                            <template slot-scope="scope">
                                <span>{{ scope.row.title }}</span>
                            </template>
                        </el-table-column>
                        <el-table-column show-overflow-tooltip label="账号状态">
                            <template slot-scope="scope">
                                <el-button
                                    :type="scope.row.accountDisabled ? 'warning' : 'success'"
                                    size="mini"
                                >
                                    {{ scope.row.accountDisabled ? '冻结' : '正常' }}
                                </el-button>
                            </template>
                        </el-table-column>
                        <el-table-column show-overflow-tooltip label="联系电话">
                            <template slot-scope="scope">
                                <span>{{ scope.row.telephone }}</span>
                            </template>
                        </el-table-column>
                        <el-table-column show-overflow-tooltip label="联系邮箱">
                            <template slot-scope="scope">
                                <span>{{ scope.row.emaiil }}</span>
                            </template>
                        </el-table-column>
                        <el-table-column label="操作" width="240" fixed="right">
                            <template slot-scope="scope">
                                <el-button
                                    type="text"
                                    @click="checkAuthoritiesFn(scope.row.code, 1)"
                                >
                                    查看权限
                                </el-button>
                                <el-button
                                    type="text"
                                    @click="addRowToGroupFn(scope.row, scope.row.code)"
                                    v-premit="'add_user_to_group'"
                                >
                                    添加到组
                                </el-button>
                                <el-button type="text" @click="showRelatedGroupsFn(scope.row.code)">
                                    已关联组
                                </el-button>
                                <el-button type="text" @click="editManageFaultyFn(scope.row)">
                                    编辑
                                </el-button>
                            </template>
                        </el-table-column>
                    </edu-table>
                </el-card>
            </div>
            <!-- 本地用户 -->
            <div id="localUserBox" v-else>
                <el-card shadow="never">
                    <el-row class="border-bottom" style="height: 56px" :gutter="20">
                        <el-col :span="6">
                            <el-input
                                placeholder="账号或用户名"
                                v-model="localUserForm.condition"
                                prefix-icon="el-icon-search"
                                clearable
                                @keyup.enter.native="queryUserList"
                            ></el-input>
                        </el-col>
                        <el-col :span="2">
                            <el-button @click="queryUserList">查询</el-button>
                        </el-col>
                        <el-col :span="4">
                            <div class="empty-box"></div>
                        </el-col>
                        <el-col :span="12">
                            <div class="float-right">
                                <el-button @click="showAddToGroupFn" v-premit="'add_user_to_group'">
                                    添加到组
                                </el-button>
                                <!-- <el-button @click="deleteLocalUser">{{$t('message.delete')}}</el-button> -->
                                <el-button
                                    @click="showAddLocalUserBox"
                                    type="primary"
                                    v-premit="'create_local_user'"
                                >
                                    {{ $t('message.add') }}
                                </el-button>
                                <span style="margin-left: 10px">能否登录：</span>
                                <el-switch
                                    active-value="1"
                                    inactive-value="0"
                                    v-model="loginMarkE.loginMark"
                                    @change="loginMarkC"
                                ></el-switch>
                            </div>
                        </el-col>
                    </el-row>
                    <edu-table
                        stripe
                        :order="false"
                        :data="localUsers"
                        style="width: 100%"
                        ref="localUserTable"
                        tooltip-effect="light"
                        :total="localUserForm.total"
                        :pageNum="localUserForm.pageNum_"
                        :page-size="localUserForm.pageSize_"
                        :isRowClickChangeRowSelection="false"
                        @page-change="(params) => handleCurrentChange(params, 'localUserForm')"
                        @selection-change="chooseUsers"
                    >
                        <el-table-column
                            prop="userId"
                            show-overflow-tooltip
                            label="账号"
                            min-width="60"
                        ></el-table-column>
                        <el-table-column
                            prop="userName"
                            label="用户名称"
                            show-overflow-tooltip
                            min-width="88"
                        ></el-table-column>
                        <el-table-column label="所属学院" show-overflow-tooltip min-width="70">
                            <template slot-scope="scope">
                                <span>{{ scope.row.deptName }}</span>
                            </template>
                        </el-table-column>
                        <el-table-column show-overflow-tooltip label="管理学院" min-width="80">
                            <template slot-scope="scope">
                                <span>{{ scope.row.manageFacultysI18n }}</span>
                            </template>
                        </el-table-column>
                        <el-table-column label="联系电话" min-width="75">
                            <template slot-scope="scope">
                                <span>{{ scope.row.mobilePhone }}</span>
                            </template>
                        </el-table-column>
                        <el-table-column label="联系邮箱" min-width="105">
                            <template slot-scope="scope">
                                <span>{{ scope.row.email }}</span>
                            </template>
                        </el-table-column>
                        <el-table-column label="操作" width="420">
                            <template slot-scope="scope">
                                <el-button
                                    type="text"
                                    @click="checkAuthoritiesFn(scope.row.userId, 3)"
                                >
                                    查看权限
                                </el-button>
                                <el-button
                                    type="text"
                                    @click="addRowToGroupFn(scope.row, scope.row.userId)"
                                    v-premit="'add_user_to_group'"
                                >
                                    添加到组
                                </el-button>
                                <el-button
                                    type="text"
                                    @click="showRelatedGroupsFn(scope.row.userId)"
                                >
                                    已关联组
                                </el-button>
                                <el-button
                                    type="text"
                                    @click="showLocalEditFn(scope.row)"
                                    v-premit="'edit_local_user'"
                                >
                                    {{ $t('message.edit') }}
                                </el-button>
                                <el-button
                                    type="text"
                                    @click="resetPwdFn(scope.row)"
                                    v-premit="'reset_local_user_pwd'"
                                >
                                    重置密码
                                </el-button>
                                <el-button
                                    type="text"
                                    @click="delLocalUserFn(scope.row.userId)"
                                    v-premit="'delete_local_user'"
                                >
                                    {{ $t('message.delete') }}
                                </el-button>
                                <el-button
                                    type="text"
                                    @click="unlockLocalUserFn(scope.row.userId)"
                                    v-premit="'delete_local_user'"
                                >
                                    {{ $t('message.unlock') }}
                                </el-button>
                            </template>
                        </el-table-column>
                    </edu-table>
                </el-card>
            </div>
        </div>
        <student-base-info v-if="indexKey == '2'" :sid="studentId" />
        <!-- 本地用户 新增弹框 -->
        <edu-dialog
            title="新增"
            width="600px"
            :autoHeight="false"
            :visible.sync="showAddLocalUserDialog"
            @close="showAddLocalUserDialog = false"
            @confirm="createLocalUser"
        >
            <el-form
                :model="newLocalUserForm"
                label-width="80px"
                label-position="right"
                class="pd-20px"
                :rules="rules"
                ref="newLocalUserForm"
            >
                <el-row>
                    <el-form-item label="账号：" prop="userId">
                        <el-input v-model="newLocalUserForm.userId" placeholder=""></el-input>
                    </el-form-item>
                </el-row>
                <el-row>
                    <el-form-item label="用户名：" prop="userName">
                        <el-input v-model="newLocalUserForm.userName" placeholder=""></el-input>
                    </el-form-item>
                </el-row>
                <el-row>
                    <el-form-item label="密码：" prop="userPwd">
                        <el-input
                            v-model="newLocalUserForm.userPwd"
                            placeholder=""
                            onpaste="return false"
                            oncopy="return false"
                            oncut="return false"
                            type="password"
                        ></el-input>
                    </el-form-item>
                </el-row>
                <el-row>
                    <el-form-item label="所属学院：" prop="deptId">
                        <el-select v-model="newLocalUserForm.deptId" style="width: 100%">
                            <el-option
                                v-for="item in depts"
                                :key="item.value"
                                :label="item.label"
                                :value="item.value"
                            />
                        </el-select>
                    </el-form-item>
                </el-row>
                <el-row>
                    <el-form-item label="联系电话：" prop="mobilePhone">
                        <el-input v-model="newLocalUserForm.mobilePhone" placeholder=""></el-input>
                    </el-form-item>
                </el-row>
                <el-row>
                    <el-form-item label="联系邮箱：" prop="email">
                        <el-input v-model="newLocalUserForm.email" placeholder=""></el-input>
                    </el-form-item>
                </el-row>
            </el-form>
        </edu-dialog>

        <!-- 本地用户 修改弹框 -->
        <edu-dialog
            title="修改"
            width="600px"
            :autoHeight="false"
            :visible.sync="showEditLocalUserDialog"
            @close="showEditLocalUserDialog = false"
            @confirm="submitLocalEditFn"
        >
            <el-form
                :model="editLocalUserForm"
                label-width="80px"
                label-position="right"
                :rules="rules"
                ref="editLocalUserForm"
            >
                <el-row>
                    <el-form-item label="账号：" prop="userId" style="width: 100%">
                        <el-input
                            v-model="editLocalUserForm.userId"
                            placeholder=""
                            readonly
                        ></el-input>
                    </el-form-item>
                </el-row>
                <el-row>
                    <el-form-item label="用户名：" prop="userName">
                        <el-input v-model="editLocalUserForm.userName" placeholder=""></el-input>
                    </el-form-item>
                </el-row>
                <el-row>
                    <el-form-item label="所属学院：" prop="deptId">
                        <el-select v-model="editLocalUserForm.deptId" style="width: 100%">
                            <el-option
                                v-for="item in depts"
                                :key="item.value"
                                :label="item.label"
                                :value="item.value"
                            />
                        </el-select>
                    </el-form-item>
                </el-row>
                <el-row>
                    <el-form-item label="管理学院：">
                        <el-select
                            multiple
                            collapse-tags
                            style="width: 100%"
                            v-model="editLocalUserForm.manageFacultys"
                        >
                            <el-option
                                v-for="item in options.manageFacultys"
                                :key="item.value"
                                :label="item.label"
                                :value="item.value"
                            ></el-option>
                        </el-select>
                    </el-form-item>
                </el-row>
                <el-row>
                    <el-form-item label="联系电话：" prop="mobilePhone">
                        <el-input v-model="editLocalUserForm.mobilePhone" placeholder=""></el-input>
                    </el-form-item>
                </el-row>
                <el-row>
                    <el-form-item label="联系邮箱：" prop="email">
                        <el-input v-model="editLocalUserForm.email" placeholder=""></el-input>
                    </el-form-item>
                </el-row>
            </el-form>
        </edu-dialog>

        <!-- 批量操作 添加到组 -->
        <edu-dialog
            :title="title"
            width="1000px"
            class="systemDialog"
            :autoHeight="false"
            :visible.sync="showAddUserToGroupBox"
            :showButtons="false"
            @close="closeAddToGroupFn"
            @click="closeAddGroupDialog"
        >
            <div v-if="batchOperate" style="height: 100%">
                <el-form class="border-bottom" style="padding: 0">
                    <el-row>
                        <el-col>
                            <el-form-item label="筛选条件:">
                                <template v-if="studentForm.trainingLevel">
                                    <el-tag>{{ conditions.trainingLevel }}</el-tag>
                                </template>
                                <template v-if="studentForm.enrolSeason">
                                    <el-tag>{{ conditions.enrolSeason }}</el-tag>
                                </template>
                                <template v-if="studentForm.grade">
                                    <el-tag>{{ conditions.grade }}</el-tag>
                                </template>
                                <template v-if="studentForm.faculty">
                                    <el-tag>{{ conditions.faculty }}</el-tag>
                                </template>
                                <template v-if="studentForm.degreeType">
                                    <el-tag>{{ conditions.degreeType }}</el-tag>
                                </template>
                                <template v-if="studentForm.profession">
                                    <el-tag>{{ conditions.profession }}</el-tag>
                                </template>
                                <template v-if="studentForm.leaveSchool">
                                    <el-tag>{{ conditions.leaveSchool }}</el-tag>
                                </template>
                                <template v-if="studentForm.name">
                                    <el-tag>{{ conditions.name }}</el-tag>
                                </template>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col>
                            <el-form-item label="筛选结果:">
                                <el-tag type="primary" size="small">{{ studentForm.total }}</el-tag>
                                &nbsp;
                                <span>条</span>
                            </el-form-item>
                        </el-col>
                    </el-row>
                </el-form>
                <el-row class="border-bottom" style="height: 56px; padding-top: 12px" :gutter="20">
                    <el-col :span="8">
                        <el-input
                            placeholder="组名"
                            suffix-icon="el-icon-search"
                            v-model="groupForm.groupName"
                            @keyup.enter.native="queryGroup"
                        ></el-input>
                    </el-col>
                    <el-col :span="2">
                        <el-button @click="queryGroup">查询</el-button>
                    </el-col>
                    <el-col :span="14">
                        <div class="float-right">
                            <template>
                                <el-button @click="batchFn('add')">批量添加到组</el-button>
                                <el-button @click="batchFn('delete')">批量解绑</el-button>
                            </template>
                        </div>
                    </el-col>
                </el-row>
                <div style="height: calc(100% - 185px); overflow: auto" key="bachOperate">
                    <el-table
                        :data="groups"
                        style="height: 100%;overflow-y: auto;"
                        class="scrollbarSty"
                        @selection-change="chooseGroups"
                        stripe
                    >
                        <el-table-column type="selection" width="42"></el-table-column>
                        <el-table-column type="index" label="序号"></el-table-column>
                        <el-table-column prop="groupName" label="组名"></el-table-column>
                    </el-table>
                </div>
                <el-row>
                    <el-col>
                        <el-pagination
                            small
                            @size-change="handleSizeChange3"
                            @current-change="handlePageNumChange3"
                            :current-page.sync="groupForm.pageNum_"
                            :page-sizes="[20, 50, 100, 500, 1000]"
                            :page-size="groupForm.pageSize"
                            layout="total, prev, pager, next"
                            :total="groupForm.total"
                            style="float: right; margin: 10px 60px 0 0"
                        ></el-pagination>
                    </el-col>
                </el-row>
            </div>

            <div v-else style="height: 100%">
                <el-row class="border-bottom" style="height: 56px; padding-top: 12px" :gutter="20">
                    <el-col :span="8">
                        <el-input
                            placeholder="组名"
                            suffix-icon="el-icon-search"
                            v-model="groupUnbindForm.groupName"
                            @keyup.enter.native="queryGroup"
                        ></el-input>
                    </el-col>
                    <el-col :span="2">
                        <el-button @click="queryGroup">查询</el-button>
                    </el-col>
                    <el-col :span="14">
                        <div class="float-right">
                            <template>
                                <el-button @click="addSelectToGroupFn">添加到组</el-button>
                            </template>
                        </div>
                    </el-col>
                </el-row>
                <div style="height: calc(100% - 92px); overflow: auto" key="unbachOperate">
                    <el-table
                        :data="groups"
                        style="height: 100%;overflow-y: auto;"
                        class="scrollbarSty"
                        @selection-change="chooseGroups"
                        stripe
                    >
                        <el-table-column type="selection" width="42"></el-table-column>
                        <el-table-column type="index" label="序号"></el-table-column>
                        <el-table-column prop="groupName" label="组名"></el-table-column>
                    </el-table>
                </div>
                <el-row>
                    <el-col>
                        <el-pagination
                            small
                            @size-change="handleSizeChange3"
                            @current-change="handlePageNumChange3"
                            :current-page.sync="groupUnbindForm.pageNum_"
                            :page-sizes="[20, 50, 100, 500, 1000]"
                            :page-size="groupUnbindForm.pageSize"
                            layout="total, prev, pager, next"
                            :total="groupUnbindForm.total"
                            style="float: right; margin: 10px 60px 0 0"
                        ></el-pagination>
                    </el-col>
                </el-row>
            </div>
        </edu-dialog>

        <!-- 已关联组 -->
        <edu-dialog
            width="1000px"
            title="已关联组"
            :autoHeight="false"
            :showButtons="false"
            :visible.sync="showRelatedGroupsDialog"
            class="systemDialog"
            @click="closeRelatedGroupDialog"
        >
            <el-row class="border-bottom" style="height: 56px" :gutter="20">
                <el-col :span="8">
                    <el-input
                        placeholder="组名"
                        v-model="relatedGroupForm.groupName"
                        suffix-icon="el-icon-search"
                        @keyup.enter.native="selectRelatedGroups"
                    ></el-input>
                </el-col>
                <el-col :span="2">
                    <el-button @click="selectRelatedGroups">查询</el-button>
                </el-col>
                <el-col :span="14">
                    <div class="float-right">
                        <!-- <el-button @click="removeUsersUnderGroup">删除</el-button> -->
                    </div>
                </el-col>
            </el-row>
            <div style="height: calc(100% - 92px); overflow: auto">
                <el-table
                    :data="relatedGroups"
                    style="height: 100%;overflow-y: auto;"
                    @selection-change="chooseRelatedGroups"
                    stripe
                >
                    <el-table-column type="index" label="序号" width="100"></el-table-column>
                    <el-table-column prop="groupName" label="组名"></el-table-column>
                    <el-table-column label="操作" width="120">
                        <template slot-scope="scope">
                            <el-button type="text" @click="removeUserUnderGroup(scope.row.groupId)">
                                解绑
                            </el-button>
                        </template>
                    </el-table-column>
                </el-table>
            </div>
            <el-row>
                <el-col>
                    <el-pagination
                        small
                        @size-change="handleSizeChange4"
                        @current-change="handlePageNumChange4"
                        :current-page="relatedGroupForm.pageNum_"
                        :page-sizes="[20, 50, 100, 500, 1000]"
                        :page-size="relatedGroupForm.pageSize_"
                        layout="total, prev, pager, next"
                        :total="relatedGroupForm.total"
                        style="float: right; margin: 10px 60px 0 0"
                    ></el-pagination>
                </el-col>
            </el-row>
        </edu-dialog>

        <!-- 本地用户 重置密码弹框 -->
        <edu-dialog
            title="重置密码"
            width="600px"
            :autoHeight="false"
            :visible.sync="showModifyPasswordDialog"
            @close="showModifyPasswordDialog"
            @confirm="submitNewPwd"
        >
            <el-form
                :model="modifyPasswordForm"
                ref="modifyPasswordForm"
                label-width="80px"
                :rules="rules1"
            >
                <el-row>
                    <el-form-item label="账号：">
                        <el-input v-model="modifyPasswordForm.userId" disabled></el-input>
                    </el-form-item>
                </el-row>
                <el-row>
                    <el-form-item label="用户名：">
                        <el-input v-model="modifyPasswordForm.userName" disabled></el-input>
                    </el-form-item>
                </el-row>
                <el-row>
                    <el-form-item label="密码：" prop="userPwd">
                        <el-input
                            v-model="modifyPasswordForm.userPwd"
                            onpaste="return false"
                            oncopy="return false"
                            oncut="return false"
                            type="password"
                        ></el-input>
                    </el-form-item>
                </el-row>
            </el-form>
        </edu-dialog>

        <!-- 查看权限弹框 -->
        <edu-dialog
            title="权限"
            width="1000px"
            class="systemDialog"
            :autoHeight="false"
            :showButtons="false"
            :visible.sync="showAuthorityDialog"
        >
            <div v-loading="loading">
                <el-row class="authority-actionBar">
                    <el-radio-group v-model="radioTypeOpt.value" size="small">
                        <el-radio-button
                            v-for="(type, index) in radioTypeOpt.data"
                            :key="index"
                            :label="type.value"
                        >
                            {{ type.name }}
                        </el-radio-button>
                    </el-radio-group>
                </el-row>
                <el-row>
                    <el-col :span="12">
                        <div
                            class="scrollbarSty"
                            style="
                                height: 330px;
                                overflow: auto;
                                border-right: 1px solid #e5e5e5;
                                margin-right: 12px;
                            "
                        >
                            <el-tree
                                empty-text="无关联权限"
                                ref="allAuthoritiesTree"
                                :data="menuTree[radioTypeOpt.value - 1]"
                                :props="defaultProps"
                                :expand-on-click-node="false"
                                @node-click="showAuthDetail"
                                node-key="authId"
                            ></el-tree>
                        </div>
                    </el-col>
                    <el-col :span="12">
                        <div style="height: 330px; overflow: auto">
                            <el-table :data="authDetails" tooltip-effect="light" stripe>
                                <el-table-column type="index" label="序号"></el-table-column>
                                <el-table-column
                                    prop="groupName"
                                    show-overflow-tooltip
                                    label="所属用户组"
                                ></el-table-column>
                                <el-table-column
                                    prop="roleName"
                                    show-overflow-tooltip
                                    label="所属角色"
                                ></el-table-column>
                            </el-table>
                        </div>
                    </el-col>
                </el-row>
            </div>
            <div slot="footer">
                <el-button @click="showAuthorityDialog = false">
                    {{ $t('message.cancel') }}
                </el-button>
            </div>
        </edu-dialog>

        <!-- 教师 编辑弹框 -->
        <edu-dialog
            title="编辑"
            width="600px"
            :visible.sync="showManageFaultyEdit"
            @confirm="confirmManageFaultyEdit"
            @close="cancelManageFaultyEdit"
        >
            <el-form label-width="100px">
                <el-form-item label="账号：">
                    <el-input disabled v-model="editManageFaultyForm.userId"></el-input>
                </el-form-item>
                <el-row>
                    <el-form-item label="用户名称：">
                        <el-input disabled v-model="editManageFaultyForm.userName"></el-input>
                    </el-form-item>
                </el-row>
                <el-row>
                    <el-form-item label="所在学院：">
                        <el-input disabled v-model="editManageFaultyForm.facultyI18n"></el-input>
                    </el-form-item>
                </el-row>
                <el-row>
                    <el-form-item label="管理学院：">
                        <el-select
                            multiple
                            collapse-tags
                            style="width: 100%"
                            v-model="editManageFaultyForm.manageFacultys"
                        >
                            <el-option
                                v-for="item in options.manageFacultys"
                                :key="item.value"
                                :label="item.label"
                                :value="item.value"
                            ></el-option>
                        </el-select>
                    </el-form-item>
                </el-row>
            </el-form>
        </edu-dialog>
    </div>
</template>
<script>
import { findStuInfoList, findTeacherInfoList } from 'common/src/api/studentinfo'
import {
    findLocalUserList,
    getGroups,
    getUnbindGroups,
    batchAddUserGroupRel,
    addLocalUser,
    deleteLocalUser,
    findAllDeptList,
    updateLocalUser,
    findGroupListByUserId,
    findGroupNotInListByUserId,
    batchDelGroupRelByUser,
    findAllInfoAuthByUserId,
    batchDelUserGroupRelByCondition,
    batchUserGroupRelByCondition,
    findGroupRoleByAuthAndUserId,
    updateLoginMark,
    getLoginMark,
    unlockLocalUser,
    updateManageDepartment,
    findManageDepartment,
    updateAccountDisabledStu,
    updateAccountDisabledTea,
} from 'common/src/api/user'
import { queryDic } from 'common/src/api/dictionary'
import md5 from 'js-md5'
import studentBaseInfo from 'common/src/views/student/studentBaseInfo'
export default {
    name: 'UserList',
    components: {
        studentBaseInfo,
    },
    computed: {
        index: () => index,
        currentUser() {
            if (this.$store.state.session.user) {
                return this.$store.state.session.user
            }
            return JSON.parse(localStorage.getItem('user'))
        },
        mockUser() {
            if (this.$store.state.session.mockUser) {
                return this.$store.state.session.mockUser
            }
            return JSON.parse(localStorage.getItem('sessiondata')).mockUser
        },
    },
    data() {
        var validateAccount = (rule, value, callback) => {
            var regex = /^[\w\d]{4,10}$/
            if (regex.test(value)) {
                callback()
            } else {
                callback(new Error('字母或数字(4~10位)'))
            }
        }
        var validatePwd = (rule, value, callback) => {
            var regSpace = /\s/
            var regLength = /^[a-zA-Z0-9\~\!\@\#\$\%\^\&\*\_\+\{\}\:\"\|\<\>\?\-\=\;\'\\\,\.\/]{6,18}$/
            var repeatReg1 = /(\w)\1{2,}/
            var repeatReg2 = /((?=[!-~]+)[^A-Za-z0-9])\1{2,}/
            var lowSafety = /^(?:\\d+|[a-zA-Z]+|[!@#$%^&*]+)$/
            var lowSafety1 = /^[a-zA-Z]{6,18}$/
            var lowSafety2 = /^[0-9]{6,18}$/
            var lowSafety3 = /((?=[!-~]+)[^A-Za-z0-9]){6,18}$/
            var midSafety1 = /^[a-zA-Z0-9]{6,18}$/
            var midSafety2 = /^(?=.*[a-zA-Z])(?=.*\d)(?=.*[~!@#$%^&*()_+`\-={}:";'<>?,.\/]).{6,10}$/
            var highSafety = /^(?=.*[a-zA-Z])(?=.*\d)(?=.*[~!@#$%^&*()_+`\-={}:";'<>?,.\/]).{11,18}$/
            var finalSafety = /^(?![a-zA-Z]+$)(?![A-Z0-9]+$)(?![A-Z\W_!@#$%^&*`~()-+=]+$)(?![a-z0-9]+$)(?![a-z\W_!@#$%^&*`~()-+=]+$)(?![0-9\W_!@#$%^&*`~()-+=]+$)[a-zA-Z0-9\W_!@#$%^&*`~()-+=]{6,18}$/
            if (regSpace.test(value)) {
                callback(new Error(this.$t('message.canNotSpace')))
            } else if (!regLength.test(value)) {
                callback(new Error(this.$t('message.pwdLength')))
            } else if (repeatReg1.test(value) || repeatReg2.test(value)) {
                callback(new Error(this.$t('message.repeatCount')))
                //} else if (lowSafety1.test(value) || lowSafety2.test(value) || lowSafety2.test(value)) {
            } else if (!finalSafety.test(value)) {
                callback(new Error(this.$t('message.characterCombination')))
                //pwdMsg = "密码强度：低";
            } else {
                callback()
            }
        }
        const getGrade = (function () {
            let now = new Date().getFullYear()
            let years = []
            for (let i = 0; i < 6; i++) {
                years.push({
                    label: now - i,
                    value: now - i,
                })
            }
            return years
        })()
        return {
            isShowDegreeType: false,
            allAuthorities: [],
            menuTree: [],
            defaultProps: {
                children: 'children',
                label: 'authNameCh',
            },
            showAuthorityDialog: false,
            loading: false,
            isEdit: false,
            showBaseOrLocal: true,
            activeTab: 'teacher',
            tabs: [
                { label: '教师', key: 'teacher' },
                { label: '学生', key: 'student' },
                { label: '本地用户', key: 'localUser' },
            ],
            showAddLocalUserDialog: false,
            showEditLocalUserDialog: false,
            showAddUserToGroupBox: false,
            showRelatedGroupsDialog: false,
            showModifyPasswordDialog: false,
            showBatchAddGroupBox: false,
            studentForm: {
                trainingLevel: '',
                grade: '',
                faculty: '',
                profession: '',
                degreeType: '',
                enrolSeason: '',
                leaveSchool: '',
                pageNum_: 1,
                total: 0,
                pageSize_: 20,
            },
            conditions: {
                trainingLevel: '',
                grade: '',
                faculty: '',
                profession: '',
                enrolSeason: '',
                leaveSchool: '',
                degreeType: '',
                name: '',
            },
            title: '',
            batchOperate: false,
            modifyPasswordForm: {
                userId: '',
                userName: '',
                userPwd: '',
            },
            teacherForm: {
                condition: '',
                pageNum_: 1,
                total: 0,
                pageSize_: 20,
            },
            groups: [],
            groupUnbindForm: {
                uid: '',
                pageNum_: 1,
                pageSize_: 20,
                groupName: '',
                total: 0,
            },
            groupForm: {
                pageNum_: 1,
                pageSize_: 20,
                groupName: '',
                total: 0,
            },
            editLocalUserForm: {},
            localUserForm: {
                condition: '',
                pageNum_: 1,
                total: 0,
                pageSize_: 20,
            },
            loginMarkE: {
                loginMark: true,
            },
            newLocalUserForm: {
                userName: '',
                description: '',
                userType: 2,
                mobilePhone: '',
                email: '',
                userPwd: '',
                deptId: '',
                userId: '',
                createBy: '',
            },
            rules: {
                userId: [
                    {
                        required: true,
                        message: '请输入账号',
                        trigger: 'blur',
                    },
                    {
                        validator: validateAccount,
                        trigger: 'blur',
                    },
                ],
                userName: [
                    {
                        required: true,
                        message: '请输入用户名',
                        trigger: 'blur',
                    },
                    {
                        max: 32,
                        message: '长度不能超过32个字符',
                        trigger: 'blur',
                    },
                ],
                userPwd: [
                    {
                        required: true,
                        message: '请输入密码',
                        trigger: 'blur',
                    },
                    {
                        validator: validatePwd,
                        trigger: 'blur',
                    },
                ],
                deptId: [
                    {
                        required: false,
                        message: '请选择所属学院',
                        trigger: 'blur',
                    },
                ],
            },
            rules1: {
                userId: [
                    {
                        required: true,
                        message: '请输入账号',
                        trigger: 'blur',
                    },
                ],
                userName: [
                    {
                        required: true,
                        message: '请输入用户名',
                        trigger: 'blur',
                    },
                ],
                userPwd: [
                    {
                        required: true,
                        message: '请输入密码',
                        trigger: 'blur',
                    },
                    {
                        validator: validatePwd,
                        trigger: 'blur',
                    },
                ],
            },
            options: {
                trainingLevel: [],
                grade: getGrade,
                faculty: [],
                degreeType: [],
                leaveSchool: [],
                enrolSeason: [],
                profession: [],
                manageFacultys: [],
            },
            students: [],
            localUsers: [],
            teachers: [],
            chosedGroups: [],
            chosedUsers: [],
            depts: [],
            currentUserId: '',
            relatedGroupForm: {
                groupName: '',
                pageNum_: 1,
                total: 0,
                pageSize_: 20,
            },
            relatedGroups: [],
            pickedRelatedGroups: [],
            functions: {},
            authDetails: [],
            radioTypeOpt: {
                value: 1,
                data: [
                    {
                        name: '管理员菜单',
                        value: 1,
                    },
                    {
                        name: '教师菜单',
                        value: 2,
                    },
                    {
                        name: '学生菜单',
                        value: 3,
                    },
                ],
            },
            showManageFaultyEdit: false,
            editManageFaultyForm: {
                userId: '',
                userName: '',
                facultyI18n: '',
                manageFacultys: [],
            },
            indexKey: '1',
            breadPath: {
                label: '用户管理',
                key: '1',
                children: [
                    {
                        key: '2',
                        label: '学生详情',
                    },
                ],
            },
            studentId: null,
            batchAddGroup: false // 是否批量添加组
        }
    },
    created() {
        this.getLoginMarkStatus()
        let user = this.mockUser ? this.mockUser : this.currentUser
        let { currentManageDptId } = user
        // 本科生 不显示学位类选
        if (currentManageDptId === '1') {
            this.isShowDegreeType = false
        } else {
            this.isShowDegreeType = true
        }
    },
    watch: {
        showAddUserToGroupBox(val) {
            if (!val) this.batchOperate = false
        },
        activeTab() {
            this.queryUserList()
        },
        'radioTypeOpt.value'(val) {
            this.authDetails = []
        },
    },
    activated() {
        this.initOptions()
    },
    methods: {
        initOptions() {
            let params = {
                lang: this.$store.getters.language || 'cn',
                type: 'allChild',
                keys: ['X_PYCC', 'X_YX', 'X_RXJJ', 'X_XWLX', 'K_ZXZT'],
            }
            queryDic(params)
                .then((res) => {
                    if (res.code == 200) {
                        this.fillSelect(res.data)
                        this.queryUserList()
                    }
                })
                .catch((error) => {
                    console.log(error)
                    this.queryUserList()
                })
        },
        async getStuInfoLis(queryForm) {
            try {
                let resp = await findStuInfoList(queryForm)
                if (resp && resp.data && resp.code == 200) {
                    this.students = resp.data.list || []
                    this.studentForm.total = resp.data.total_ || 0
                } else {
                    this.setDataFormatErrMsg()
                }
            } catch (error) {
                console.log(error)
            }
        },
        async getTeacherInfoList(queryForm) {
            try {
                let resp = await findTeacherInfoList(queryForm)
                if (resp && resp.data && resp.code == 200) {
                    this.teachers = resp.data.list || []
                    this.teacherForm.total = resp.data.total || 0
                } else {
                    this.setDataFormatErrMsg()
                }
            } catch (error) {
                console.log(error)
            }
        },
        async getLocalUserList(queryForm) {
            try {
                let resp = await findLocalUserList(queryForm)
                if (resp && resp.data && resp.code == 200) {
                    this.localUsers = resp.data.list || []
                    this.localUserForm.total = resp.data.total_ || 0
                } else {
                    this.setDataFormatErrMsg()
                }
            } catch (error) {
                console.log(error)
            }
        },
        async getLoginMark() {
            try {
                let resp = await getLoginMark()
                if (resp && resp.code == 200) {
                    this.loginMarkE.loginMark = resp.data
                } else {
                    this.setDataFormatErrMsg()
                }
            } catch (error) {
                console.log(error)
            }
        },
        async getGroupsList(queryForm) {
            try {
                let resp = await getGroups(queryForm)
                return resp
            } catch (error) {
                console.log(error)
            }
        },
        async getUnbindGroupsList(queryForm) {
            try {
                let resp = await getUnbindGroups(queryForm)
                if (resp && resp.data && resp.code == 200) {
                    this.groups = resp.data.list
                    this.groupUnbindForm.total = resp.data.total_
                } else {
                    this.setDataFormatErrMsg()
                }
            } catch (error) {
                console.log(error)
            }
        },
        async batchAddUserGroupRel(queryForm) {
            try {
                let resp = await batchAddUserGroupRel(queryForm)
                if (resp && resp.code == 200) {
                    this.$message({
                        type: 'success',
                        message: '操作成功',
                    })
                    this.showAddUserToGroupBox = false
                } else {
                    this.$message({
                        type: 'error',
                        message: '操作失败, 请重试',
                    })
                }
            } catch (error) {
                console.log(error)
            }
        },
        async addLocalUser(queryForm) {
            try {
                let resp = await addLocalUser(queryForm)
                if (resp && resp.code) {
                    this.$message({
                        type: 'success',
                        message: '添加成功',
                    })
                    this.queryLocalUser()
                    this.showAddLocalUserDialog = false
                    this.$refs.newLocalUserForm.resetFields()
                } else {
                    this.$message({
                        type: 'error',
                        message: resp.msg,
                    })
                }
            } catch (error) {
                console.log(error)
            }
        },
        async deleteLocalUser(queryForm) {
            try {
                let resp = await deleteLocalUser(queryForm)
                if (resp && resp.code) {
                    this.queryUserList()
                    this.$message({
                        type: 'success',
                        message: '删除成功',
                    })
                } else {
                    this.$message({
                        type: 'error',
                        message: '操作失败',
                    })
                }
            } catch (error) {
                console.log(error)
            }
        },
        async findAllDeptList(deptId) {
            try {
                let resp = await findAllDeptList()
                if (resp && resp.code == 200) {
                    let list = this.switchData(resp.data)
                    this.depts = this.$utils.listToTree('value', 'pValue', list)
                    // this.editLocalUserForm.deptId = [deptId];
                    deptId && this.$set(this.editLocalUserForm, 'deptId', deptId)
                } else {
                    this.$message({
                        type: 'error',
                        message: '初始化部门列表失败.',
                    })
                }
            } catch (error) {
                console.log(error)
            }
        },
        async updateLocalUser(queryForm, resetPwd = false) {
            try {
                let resp = await updateLocalUser(queryForm)
                if (resp && resp.code == 200) {
                    this.$message({
                        type: 'success',
                        message: '修改成功',
                    })
                    this.queryLocalUser()
                    if (resetPwd) {
                        this.showModifyPasswordDialog = false
                        this.$refs.modifyPasswordForm.resetFields()
                    } else {
                        this.showEditLocalUserDialog = false
                        this.$refs.editLocalUserForm.resetFields()
                    }
                } else {
                    let msg = resetPwd ? '重置密码失败, 请重试' : '编辑出错, 请重试!'
                    this.$message({
                        type: 'error',
                        message: msg,
                    })
                }
            } catch (error) {
                console.log(error)
            }
        },
        async getGroupListByUserId(queryForm) {
            try {
                let resp = await findGroupListByUserId(queryForm)
                if (resp && resp.code == 200) {
                    this.relatedGroups = resp.data.list
                    this.relatedGroupForm.total = resp.data.total_
                } else {
                    this.setDataFormatErrMsg()
                }
            } catch (error) {
                console.log(error)
            }
        },
        async getGroupNotInListByUserId(queryForm) {
            try {
                let resp = await findGroupNotInListByUserId(queryForm)
                if (resp && resp.data) {
                    this.groups = resp.data.list
                } else {
                    this.setDataFormatErrMsg()
                }
            } catch (error) {
                console.log(error)
            }
        },
        async batchDelGroupRelByUser(queryForm) {
            let resp = await batchDelGroupRelByUser(queryForm)
            if (resp && resp.code == 200) {
                this.$message({
                    type: 'success',
                    message: '操作成功',
                })
                this.selectRelatedGroups()
            } else {
                this.$message({
                    type: 'error',
                    message: '操作失败',
                })
            }
        },
        async getUserAuthorityTree(queryForm) {
            try {
                const resp = await Promise.all([
                    findAllInfoAuthByUserId(queryForm + '1'),
                    findAllInfoAuthByUserId(queryForm + '2'),
                    findAllInfoAuthByUserId(queryForm + '3'),
                ])
                let menuTree = []
                if (_.isArray(resp)) {
                    resp.forEach((item) => {
                        if (item.code === 200) {
                            menuTree.push(
                                this.$utils.listToTree('authId', 'parentAuthId', item.data)
                            )
                        }
                    })
                    this.menuTree = menuTree
                    this.loading = false
                }
            } catch (error) {
                console.log(error)
                this.loading = false
                this.menuTree = []
            }
        },
        async batchDelUserGroupRelByCondition(queryForm) {
            let resp = await batchDelUserGroupRelByCondition(queryForm)
            if (resp.code == 200) {
                this.$message({
                    type: 'success',
                    message: '操作成功',
                })
                this.showAddUserToGroupBox = false
            } else {
                this.$message({
                    type: 'error',
                    message: '操作失败',
                })
            }
        },
        async batchUserGroupRelByCondition(queryForm) {
            let resp = await batchUserGroupRelByCondition(queryForm)
            if (resp && resp.code) {
                this.$message({
                    type: 'success',
                    message: '操作成功',
                })
                this.showAddUserToGroupBox = false
            } else {
                this.$message({
                    type: 'error',
                    message: '操作失败',
                })
            }
        },
        async findGroupRoleByAuthAndUserId(userId, authId) {
            try {
                let resp = await findGroupRoleByAuthAndUserId(userId, authId)
                if (resp && resp.data && resp.code == 200) {
                    this.authDetails = resp.data
                    this.$message({
                        type: 'success',
                        message: '查询成功',
                    })
                } else {
                    this.$message({
                        type: 'error',
                        message: '查询失败',
                    })
                }
            } catch (error) {
                console.log(error)
            }
        },
        async updateLoginMark(queryForm) {
            try {
                let resp = await updateLoginMark(queryForm)
                if (resp && resp.code == 200) {
                    this.$message({
                        type: 'success',
                        message: '修改成功',
                    })
                } else {
                    this.$message({
                        type: 'error',
                        message: '修改失败',
                    })
                }
            } catch (error) {
                console.log(error)
            }
        },
        async unlockLocalUser(queryForm) {
            try {
                let resp = await unlockLocalUser(queryForm)
                if (resp && resp.code == 200) {
                    this.queryUserList()
                    this.$message({
                        type: 'success',
                        message: '解锁成功',
                    })
                } else {
                    this.$message({
                        type: 'error',
                        message: '操作失败',
                    })
                }
            } catch (error) {
                console.log(error)
            }
        },
        async updateManageDepartment(queryForm) {
            try {
                let resp = await updateManageDepartment(queryForm)
                if (resp && resp.code == 200) {
                    this.showManageFaultyEdit = false
                    this.queryTeachers()
                }
            } catch (error) {
                console.log(error)
            }
        },
        async findManageDepartment(queryForm) {
            try {
                let resp = await findManageDepartment(queryForm)
                return resp
            } catch (error) {
                console.log(error)
            }
        },
        setDataFormatErrMsg() {
            this.$message({
                type: 'error',
                message: 'The data returned is malformed',
            })
        },
        getLoginMarkStatus() {
            this.getLoginMark()
        },
        /**
         * 批量操作类型
         * @param type {string} 批量操作的类型
         */
        batchFn(type) {
            let len = this.chosedGroups.length
            if (len != 1) {
                this.$message({
                    type: 'warning',
                    message: len == 0 ? '请选择一个用户组' : '仅能批量操作一个用户组.',
                })
                return
            }
            this.$confirm('将按照查询条件批量操作, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning',
            })
                .then(() => {
                    let condition = this.getCondition()
                    if (type == 'add') {
                        this.batchAdd(condition)
                    } else {
                        this.batchDel(condition)
                    }
                })
                .catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消操作',
                    })
                })
        },
        getCondition() {
            let condition = {
                groupId: this.chosedGroups[0].groupId,
                userType: '2',
            }
            for (let key in this.studentForm) {
                let value = this.studentForm[key]
                if (value) condition[key] = value
            }
            return condition
        },
        /**
         * 批量增加 学生批量操作弹框
         */
        batchAdd(condition) {
            this.batchUserGroupRelByCondition(condition)
        },
        /**
         * 批量删除 学生批量操作弹框
         */
        batchDel(condition) {
            this.batchDelUserGroupRelByCondition(condition)
        },
        showAuthDetail(item, node, tree) {
            let userId = this.currentUserId
            let authId = node.key
            this.findGroupRoleByAuthAndUserId(userId, authId)
        },
        /**
         * 查看权限
         * @param userId {String}
         * @param type {String}
         */
        checkAuthoritiesFn(userId, type) {
            if (!userId || !type) return
            this.authDetails = []
            this.radioTypeOpt.value = 1
            this.loading = true
            this.showAuthorityDialog = true
            this.currentUserId = userId
            let query = 'userId=' + userId + '&type=1' + '&roleType='
            let menuTree = []
            this.menuTree = []
            this.getUserAuthorityTree(query)
        },
        /**
         * 批量操作 显示弹框
         */
        showBatchFn() {
            this.batchAddGroup = false
            this.showAddUserToGroupBox = true
            this.transConditions()
            this.batchOperate = true
            this.title = '批量操作'
            this.groupForm.groupName = ''
            this.groupForm.pageNum_ = 1
            this.groupForm.pageSize_ = 20
            this.queryGroup()
        },
        transConditions() {
            for (let key in this.conditions)
                if (key == 'name' || key == 'grade') this.conditions[key] = this.studentForm[key]
                else this.conditions[key] = this.getLabel(key, this.studentForm[key])
        },
        getLabel(type, key) {
            if (this.options[type] && key) {
                let items = this.options[type].filter((item) => {
                    return item.value == key
                })
                return items[0].label
            } else return ''
        },
        /**
         * 重置 学生筛选条件
         */
        resetStuQueryForm() {
            // this.$refs['studentForm'].resetFields();
            this.studentForm.trainingLevel = ''
            this.studentForm.grade = ''
            this.studentForm.faculty = ''
            ;(this.studentForm.degreeType = ''),
                (this.studentForm.enrolSeason = ''),
                (this.studentForm.profession = '')
            this.studentForm.leaveSchool = ''
            this.studentForm.pageNum_ = 1
            this.studentForm.total = 0
            this.studentForm.pageSize_ = 20
            this.queryUserList()
        },
        /**
         * 重置密码 本地用户
         */
        resetPwdFn(user) {
            this.showModifyPasswordDialog = true
            this.modifyPasswordForm.userId = user.userId
            this.modifyPasswordForm.userName = user.userName
        },
        submitNewPwd() {
            this.$refs.modifyPasswordForm.validate((valid) => {
                if (valid) {
                    this.modifyPasswordForm.userPwd = md5(md5(this.modifyPasswordForm.userPwd))
                    this.updateLocalUser(this.modifyPasswordForm)
                }
            })
        },
        handleCurrentChange(val, mode) {
            console.log(val, mode)
            this[mode].pageSize_ = val.pageSize
            this[mode].pageNum_ = val.pageNum
            let actions = {
                studentForm: this.queryStudents(),
                teacherForm: this.queryTeachers(),
                localUserForm: this.queryLocalUser(),
            }
            return actions[mode]
        },
        handleSizeChange3(val) {
            if (this.batchOperate) {
                this.groupForm.pageSize_ = val
            } else {
                this.groupUnbindForm.pageSize_ = val
            }
            this.queryGroup()
        },
        handlePageNumChange3(val) {
            if (this.batchOperate) {
                this.groupForm.pageNum_ = val
            } else {
                this.groupUnbindForm.pageNum_ = val
            }
            this.queryGroup()
        },
        handleSizeChange4(val) {
            this.relatedGroupForm.pageSize_ = val
            this.selectRelatedGroups()
        },
        handlePageNumChange4(val) {
            this.relatedGroupForm.pageNum_ = val
            this.selectRelatedGroups()
        },
        closeRelatedGroupDialog() {
            this.relatedGroups.splice(0, this.relatedGroups.length)
        },
        closeAddGroupDialog() {
            this.groups.splice(0, this.groups.length)
        },

        chooseRelatedGroups(relatedGroups) {
            this.pickedRelatedGroups = relatedGroups
        },
        removeUserUnderGroup(groupId) {
            let userId = this.currentUserId
            if (!groupId) return
            if (!userId) return
            let userType = this.activeTab == 'student' ? 2 : this.activeTab == 'teacher' ? 1 : 3
            let data = {
                userId: userId,
                groupList: [
                    {
                        groupId: groupId,
                        userType: userType,
                    },
                ],
            }
            this.batchDelGroupRelByUser(data)
        },
        removeUsersUnderGroup() {},
        selectRelatedGroups() {
            if (!this.currentUserId) {
                return
            }
            this.relatedGroupForm.userId = this.currentUserId
            this.getGroupListByUserId(this.relatedGroupForm)
        },
        showRelatedGroupsFn(userId) {
            this.currentUserId = userId
            this.showRelatedGroupsDialog = true
            this.selectRelatedGroups()
        },
        changeFaculty(val) {
            this.options['profession'] = []
            let { degreeType, grade, faculty } = this.studentForm
            let params = {
                lang: this.$store.getters.language || 'cn',
                type: 'allChild',
                keys: ['G_ZY'],
                filter: {
                    prefix: [val],
                    specilaCode: 'XY2ZY',
                    facultys: faculty ? [faculty] : [],
                    grade: grade,
                    degreeType: degreeType ? [degreeType] : [],
                },
            }
            queryDic(params)
                .then((res) => {
                    if (res.code == 200) this._fill('profession', res.data.G_ZY)
                })
                .catch((error) => {
                    console.log(error)
                })
        },
        fillSelect(data) {
            this._fill('trainingLevel', data.X_PYCC)
            this._fill('faculty', data.X_YX)
            this._fill('enrolSeason', data.X_RXJJ)
            this._fill('degreeType', data.X_XWLX)
            this._fill('leaveSchool', data.K_ZXZT)
        },
        _fill(type, data) {
            this.options[type] = []
            for (let key in data) {
                this.options[type].push({
                    value: key,
                    label: data[key],
                })
            }
        },
        /**
         * 查询组名 添加到组弹窗
         */
        queryGroup() {
            if (!this.batchOperate) {
              if (this.batchAddGroup) {
                // 通过批量添加按钮进入时
                const params = Object.assign({}, {...this.groupUnbindForm}, {uid: undefined})
                this.getGroupsList(params).then((resp) => {
                    if (resp && resp.data && resp.code == 200) {
                        this.groups = resp.data.list
                        this.groupUnbindForm.total = resp.data.total_
                    } else {
                        this.setDataFormatErrMsg()
                    }
                })
              } else {
                // 通过列表按钮进入时
                this.getUnbindGroupsList(this.groupUnbindForm)
              }
            } else {
                this.getGroupsList(this.groupForm).then((resp) => {
                    if (resp && resp.data && resp.code == 200) {
                        this.groups = resp.data.list
                        this.groupForm.total = resp.data.total_
                    } else {
                        this.setDataFormatErrMsg()
                    }
                })
            }
        },
        selectNotRelatedGroups() {
            this.getGroupNotInListByUserId(this.groupUnbindForm)
        },
        getUserIds() {
            return this.chosedUsers.map((item) => {
                if (this.activeTab == 'student')
                    return {
                        userId: item.studentId,
                        userName: item.name,
                    }
                else if (this.activeTab == 'teacher') {
                    return {
                        userId: item.code,
                        userName: item.name,
                    }
                } else
                    return {
                        userId: item.userId,
                        userName: item.userName,
                    }
            })
        },
        /**
         * 添加到组 所选批量操作
         */
        addSelectToGroupFn() {
            let data = {
                groupIdList: this.getGroupIds(),
                userType: this.activeTab == 'student' ? 2 : this.activeTab == 'teacher' ? 1 : 3,
                userList: this.getUserIds(),
            }
            if (!data.groupIdList.length) {
                this.$message({
                    type: 'warning',
                    message: '请选择用户组',
                })
                return
            }
            this.batchAddUserGroupRel(data)
        },
        getGroupIds() {
            return this.chosedGroups.map((item, index) => {
                return item.groupId
            })
        },
        /**
         * 添加到组 行操作
         * @param user {Object} 用户
         * @param uid {String} 用户uid
         */
        addRowToGroupFn(user, uid) {
            this.batchAddGroup = false
            this.showAddUserToGroupBox = true
            this.chosedUsers = []
            this.chosedUsers.push(user)
            this.title = '添加用户到组'
            this.groupUnbindForm.uid = uid
            this.groupUnbindForm.groupName = ''
            this.groupUnbindForm.pageNum_ = 1
            this.groupUnbindForm.pageSize_ = 20
            this.queryGroup()
        },

        toggleTab(tab) {
            this.activeTab = tab
            this.queryUserList()
        },
        /**
         * 查询用户列表
         */
        queryUserList() {
            if (this.activeTab == 'localUser') {
                this.queryLocalUser()
            } else if (this.activeTab == 'teacher') {
                this.queryTeachers()
            } else {
                this.queryStudents()
            }
        },
        queryTeachers() {
            this.getTeacherInfoList(this.teacherForm)
        },
        queryStudents() {
            let {
                name,
                trainingLevel,
                grade,
                faculty,
                profession,
                degreeType,
                enrolSeason,
                leaveSchool,
                pageNum_,
                total,
                pageSize_,
            } = this.studentForm
            let studentForm = {
                trainingLevelList: trainingLevel ? trainingLevel.split(',') : [],
                facultyList: faculty ? faculty.split(',') : [],
                professionList: profession ? profession.split(',') : [],
                name,
                grade,
                degreeType,
                enrolSeason,
                leaveSchool,
                pageNum_,
                total,
                pageSize_,
            }
            this.getStuInfoLis(studentForm)
        },

        /**
         * 添加到组 显示弹框
         */
        showAddToGroupFn() {
            if (this.chosedUsers.length == 0) {
                this.$message({
                    type: 'warning',
                    message: '请选择用户',
                })
                return
            } else {
                this.batchAddGroup = true
                this.showAddUserToGroupBox = true
                this.title = '添加到组'
                this.groupUnbindForm.groupName = ''
                this.groupUnbindForm.pageNum_ = 1
                this.groupUnbindForm.pageSize_ = 20
                this.getGroupsList({
                    pageNum_: 1,
                    pageSize_: 20,
                }).then((resp) => {
                    if (resp && resp.data && resp.code == 200) {
                        this.groups = resp.data.list
                        this.groupUnbindForm.total = resp.data.total_
                    } else {
                        this.setDataFormatErrMsg()
                    }
                })
            }
        },
        chooseGroups(val) {
            this.chosedGroups = val
        },
        chooseUsers(val) {
            this.chosedUsers = val
        },
        addGroupsBatch() {},
        addToUserGroup() {},
        delLocalUserFn(userId) {
            let _that = this
            this.$confirm('确定要删除该记录吗?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning',
            })
                .then(() => {
                    _that.deleteLocalUser({
                        userId,
                    })
                })
                .catch((error) => {
                    console.log(error)
                })
        },
        unlockLocalUserFn(userId) {
            let _that = this
            this.$confirm('此账户次日将自动解锁,确定要立即解锁吗?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning',
            })
                .then(() => {
                    this.unlockLocalUser(userId)
                })
                .catch((error) => {
                    console.log(error)
                })
        },
        deleteLocalUsers() {},
        deleteLocalUserBatch() {},
        cancelCreate() {
            this.$refs.newLocalUserForm.resetFields()
        },
        showAddLocalUserBox() {
            this.showAddLocalUserDialog = true
            this.newLocalUserForm.createBy = this.$store.state.session.user.name
            this.queryDepts()
        },
        queryDepts(deptId = '') {
            this.findAllDeptList(deptId)
        },
        switchData(list) {
            return list.map((item, index) => {
                return {
                    value: item.deptId,
                    label: item.deptName,
                    pValue: item.parentDeptId,
                }
            })
        },
        createLocalUser() {
            this.$refs.newLocalUserForm.validate((valid) => {
                if (valid) {
                    this.newLocalUserForm.userPwd = md5(md5(this.newLocalUserForm.userPwd))
                    this.addLocalUser(this.newLocalUserForm)
                }
            })
        },
        /**
         * 显示 本地用户编辑弹框
         */
        showLocalEditFn(localUser) {
            console.log(localUser)
            let { userId, userName, deptId, manageFacultys, mobilePhone, email } = localUser
            this.queryDepts(deptId)
            this.findManageDepartment({
                userType: 3,
                userId: userId,
            }).then((resp) => {
                if (resp && resp.data && resp.code == 200) {
                    let manageFacultysList = (resp.data && resp.data.manageFacultyList) || {}
                    this._fill('manageFacultys', manageFacultysList)
                    manageFacultys = (manageFacultys && manageFacultys.split(',')) || []
                    this.editLocalUserForm = {
                        userId,
                        userName,
                        deptId,
                        manageFacultys,
                        mobilePhone,
                        email,
                    }
                    this.showEditLocalUserDialog = true
                }
            })
        },
        /**
         * 提交 本地用户编辑
         */
        submitLocalEditFn() {
            let that = this
            this.$refs.editLocalUserForm.validate((valid) => {
                if (valid) {
                    let {
                        userId,
                        userName,
                        deptId,
                        manageFacultys,
                        mobilePhone,
                        email,
                    } = this.editLocalUserForm
                    this.updateLocalUser({
                        userId,
                        userName,
                        deptId,
                        manageFacultys: manageFacultys.join(','),
                        mobilePhone,
                        email,
                    })
                }
            })
        },
        /**
         * 查询 本地用户
         */
        queryLocalUser() {
            this.getLocalUserList(this.localUserForm)
        },
        loginMarkC(status) {
            this.loginMarkE.loginMark = status
            this.updateLoginMark(this.loginMarkE)
        },
        /**
         * 编辑 教师管理学院
         */
        editManageFaultyFn(data) {
            this.showManageFaultyEdit = true
            let { code: userId, name: userName, facultyI18n, manageFacultys } = data
            this.findManageDepartment({
                userType: 1,
                userId: userId,
            }).then((resp) => {
                if (resp && resp.data && resp.code == 200) {
                    let manageFacultysList = (resp.data && resp.data.manageFacultyList) || {}
                    this._fill('manageFacultys', manageFacultysList)
                    manageFacultys = (manageFacultys && manageFacultys.split(',')) || []
                    this.editManageFaultyForm = {
                        userId,
                        userName,
                        facultyI18n,
                        manageFacultys: manageFacultys,
                    }
                }
            })
        },
        cancelManageFaultyEdit() {
            this.showManageFaultyEdit = false
        },
        confirmManageFaultyEdit() {
            let { userId, manageFacultys } = this.editManageFaultyForm
            // 管理学院更新
            this.updateManageDepartment({
                code: userId,
                manageFacultys: manageFacultys.join(','),
            })
        },
        /**
         * 关闭添加到组 弹窗
         * 清空选中值及状态
         */
        closeAddToGroupFn() {
            this.chosedUsers = []
            this.chosedGroups = []
            this.$refs.stuUserTable && this.$refs.stuUserTable.clearSelection()
            this.$refs.teacherUserTable && this.$refs.teacherUserTable.clearSelection()
            this.$refs.localUserTable && this.$refs.localUserTable.clearSelection()
        },
        showStudentDetail(studentId) {
            this.studentId = studentId
            this.indexKey = '2'
        },
        /**
         * 账号冻结激活
         * mode 0:激活；1：冻结
         */
        freeze(mode) {
            let _this = this
            if (_this.chosedUsers.length == 0) {
                this.$message({
                    type: 'warning',
                    message: '请选择用户',
                })
                return
            }
            _this
                .$confirm(`确认${mode ? '冻结' : '激活'}选中账号, 是否继续?`, '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning',
                })
                .then(() => {
                    let fn
                    if (_this.activeTab == 'teacher') {
                        fn = function (item) {
                            return {
                                code: item.code,
                                accountDisabled: mode,
                            }
                        }
                    } else {
                        fn = function (item) {
                            return {
                                studentId: item.studentId,
                                accountDisabled: mode,
                            }
                        }
                    }
                    _this.updateAccountDisabled(fn)
                })
        },
        async updateAccountDisabled(fn) {
            let list = this.chosedUsers.map(fn)
            let api =
                this.activeTab == 'teacher' ? updateAccountDisabledTea : updateAccountDisabledStu
            let { code } = await api(list)
            if (code !== 200) return
            this.activeTab == 'teacher' ? this.queryTeachers() : this.queryStudents()
        },
    },
}
</script>

<style lang="scss" scoped>
.edu-page-title {
    span {
        cursor: pointer;
        display: inline-block;
        padding-right: 20px;
    }
    span.active {
        color: #66b1ff;
    }
}
.authority-actionBar {
    margin-bottom: 16px;
}
</style>
